<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<meta name="theme-color" content="#222"><meta name="generator" content="Hexo 6.3.0">

  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/favicon.ico">
  <link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.ico">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">



<link rel="stylesheet" href="https://unpkg.com/@fortawesome/fontawesome-free@6.2.0/css/all.min.css" integrity="sha256-AbA177XfpSnFEvgpYu1jMygiLabzPCJCRIBtR5jGc0k=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://unpkg.com/animate.css@3.1.1/animate.min.css" integrity="sha256-PR7ttpcvz8qrF57fur/yAx1qXMFJeJFiA6pSzWi0OIE=" crossorigin="anonymous">

<script class="next-config" data-name="main" type="application/json">{"hostname":"blog.csgrandeur.com","root":"/","images":"/images","scheme":"Gemini","darkmode":false,"version":"8.13.2","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12},"copycode":{"enable":true,"style":"default"},"bookmark":{"enable":false,"color":"#222","save":"auto"},"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"stickytabs":false,"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"prism":false,"i18n":{"placeholder":"搜索...","empty":"没有找到任何搜索结果：${query}","hits_time":"找到 ${hits} 个搜索结果（用时 ${time} 毫秒）","hits":"找到 ${hits} 个搜索结果"},"path":"/search.xml","localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false}}</script><script src="/js/config.js"></script>

    <meta name="description" content="凸优化是个大话题，常见却又从未系统去理解，这里做一些初步了解。">
<meta property="og:type" content="article">
<meta property="og:title" content="凸优化初步了解">
<meta property="og:url" content="https://blog.csgrandeur.com/2021-04-24-understanding-of-convex-optimization/index.html">
<meta property="og:site_name" content="CSGrandeur&#39;s Thinking">
<meta property="og:description" content="凸优化是个大话题，常见却又从未系统去理解，这里做一些初步了解。">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2021-04-24T02:58:02.000Z">
<meta property="article:modified_time" content="2021-05-23T07:43:26.383Z">
<meta property="article:author" content="CSGrandeur">
<meta name="twitter:card" content="summary">


<link rel="canonical" href="https://blog.csgrandeur.com/2021-04-24-understanding-of-convex-optimization/">



<script class="next-config" data-name="page" type="application/json">{"sidebar":"","isHome":false,"isPost":true,"lang":"zh-CN","comments":true,"permalink":"https://blog.csgrandeur.com/2021-04-24-understanding-of-convex-optimization/","path":"2021-04-24-understanding-of-convex-optimization/","title":"凸优化初步了解"}</script>

<script class="next-config" data-name="calendar" type="application/json">""</script>
<title>凸优化初步了解 | CSGrandeur's Thinking</title>
  
  <script class="next-config" data-name="google_analytics" type="application/json">{"tracking_id":"UA-69787882-2","only_pageview":true}</script>
  <script src="/js/third-party/analytics/google-analytics.js"></script>






  <noscript>
    <link rel="stylesheet" href="/css/noscript.css">
  </noscript>
</head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏" role="button">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <i class="logo-line"></i>
      <p class="site-title">CSGrandeur's Thinking</p>
      <i class="logo-line"></i>
    </a>
      <p class="site-subtitle" itemprop="description">Cogito Ergo Sum</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu"><li class="menu-item menu-item-home"><a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a></li><li class="menu-item menu-item-categories"><a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类</a></li><li class="menu-item menu-item-archives"><a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档</a></li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup"><div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off" maxlength="80"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close" role="button">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div class="search-result-container no-result">
  <div class="search-result-icon">
    <i class="fa fa-spinner fa-pulse fa-5x"></i>
  </div>
</div>

    </div>
  </div>

</div>
        
  
  <div class="toggle sidebar-toggle" role="button">
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
  </div>

  <aside class="sidebar">

    <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <div class="post-toc-wrap sidebar-panel">
            <div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E4%BC%98%E5%8C%96optimization"><span class="nav-number">1.</span> <span class="nav-text">优化（optimization）</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%87%B8%E9%9B%86"><span class="nav-number">2.</span> <span class="nav-text">凸集</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%87%B8%E5%87%BD%E6%95%B0"><span class="nav-number">3.</span> <span class="nav-text">凸函数</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%87%B8%E4%BC%98%E5%8C%96"><span class="nav-number">4.</span> <span class="nav-text">凸优化</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%B1%80%E9%83%A8%E6%9C%80%E4%BC%98%E4%B8%8E%E5%85%A8%E5%B1%80%E6%9C%80%E4%BC%98"><span class="nav-number">5.</span> <span class="nav-text">局部最优与全局最优</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%B1%82%E8%A7%A3"><span class="nav-number">6.</span> <span class="nav-text">求解</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%B0%8F%E7%BB%93"><span class="nav-number">7.</span> <span class="nav-text">小结</span></a></li></ol></div>
        </div>
        <!--/noindex-->

        <div class="site-overview-wrap sidebar-panel">
          <div class="site-author site-overview-item animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">CSGrandeur</p>
  <div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap site-overview-item animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
        <a href="/archives/">
          <span class="site-state-item-count">30</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
          <a href="/categories/">
        <span class="site-state-item-count">5</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
          <a href="/tags/">
        <span class="site-state-item-count">21</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>



        </div>
      </div>
    </div>
  </aside>
  <div class="sidebar-dimmer"></div>


    </header>

    
  <div class="back-to-top" role="button" aria-label="返回顶部">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


    <div class="main-inner post posts-expand">


  


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://blog.csgrandeur.com/2021-04-24-understanding-of-convex-optimization/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="CSGrandeur">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="CSGrandeur's Thinking">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="post" itemscope itemtype="http://schema.org/CreativeWork">
      <meta itemprop="name" content="凸优化初步了解 | CSGrandeur's Thinking">
      <meta itemprop="description" content="">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          凸优化初步了解
        </h1>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2021-04-24 10:58:02" itemprop="dateCreated datePublished" datetime="2021-04-24T10:58:02+08:00">2021-04-24</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar-check"></i>
      </span>
      <span class="post-meta-item-text">更新于</span>
      <time title="修改时间：2021-05-23 15:43:26" itemprop="dateModified" datetime="2021-05-23T15:43:26+08:00">2021-05-23</time>
    </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
        <p>凸优化是个大话题，常见却又从未系统去理解，这里做一些初步了解。</p>
<span id="more"></span>
<h2 id="优化optimization">优化（optimization）</h2>
<p>机器学习的大部分事情，就是把任务建模成一个优化问题：</p>
<p><span class="math display">\[
\min_{x\in D} f(x)
\]</span></p>
<p>用高中数学的用词来讲，就是让 <span class="math inline">\(x\)</span> 在定义域 <span class="math inline">\(D\)</span> 上找到特定位置，使 <span class="math inline">\(f(x)\)</span> 达到最小值。</p>
<p>机器学习中，我们通常用梯度下降、牛顿迭代等方法来找最优解，也就是利用函数的导数，或数据的梯度，来迭代地找到达到最优解的优化变量的位置。</p>
<p>我们曾经学函数的时候直到，可以利用“导数=0”来求最大或最小值，也知道对于一些函数，这个方法是不适用的，比如三次函数，拐点梯度为0但并不是最大或最小值。显然，二次函数的形状是“凸的”，三次函数则不是。</p>
<p>如果机器学习中的问题能够适用“梯度为0则为最优解”，或问题可以转换成适用的问题，那么优化问题就会变简单。那么我们可以对问题做限定：</p>
<ol type="1">
<li>函数是凸函数</li>
<li>优化变量的可行域是凸集</li>
</ol>
<h2 id="凸集">凸集</h2>
<p>通过二次函数与三次函数，凸函数还算容易理解。那么凸集是什么呢？</p>
<p>对于<code>n</code>维空间集合<code>D</code>中任意两点 <span class="math inline">\(p_{1}\)</span> 与 <span class="math inline">\(p_{2}\)</span> ， 对 <span class="math inline">\(\theta \in [0, 1]\)</span> 都有</p>
<p><span class="math display">\[
\theta p_{1} + (1-\theta)p_{2} \in D
\]</span></p>
<p>则该集合<code>D</code>是凸集。</p>
<p>也比较显而易见，用二维空间理解的话，就是没有洞也没有凹槽。</p>
<p>显然在不加约束的情况下，任意维度空间都满足上面公式，即都是凸集。</p>
<p>那么如果作为一个课程，就可以出不少有意思的考试题了：给不同类型的约束，证明约束下的可行域是否是凸集。</p>
<p>比如线性规划：如果每条直线都取一侧作为可行域，一系列直线的交集肯定是个凸集。</p>
<ul>
<li>多个凸集的交集也是凸集</li>
<li>线性等式约束可行域是凸集</li>
</ul>
<h2 id="凸函数">凸函数</h2>
<p>在定义域内，任意两点 <span class="math inline">\(p_{1}\)</span> 与 <span class="math inline">\(p_{2}\)</span> ，都满足</p>
<p><span class="math display">\[
f(\theta p_{1} + (1 - \theta)p_{2}) \leq \theta f(p_{1}) + (1 - \theta)f(p_{2})
\]</span></p>
<p>则 <code>f</code> 是凸函数。</p>
<p>当然，实际问题中往往不那么直观，就会有更多数学工具与方法来证明函数凸性，比如海瑟矩阵是否正定等等，读研时候学过，早忘一干二净了。。。</p>
<h2 id="凸优化">凸优化</h2>
<p>如果一个最优化问题的可行域是凸集，并且目标函数是凸函数，则该问题为凸优化问题。</p>
<p>证明一个优化问题是凸优化，就从以上内容着手，证明凸函数一般就证明海瑟矩阵半正定，证明可行域是凸集就可以利用许多已有的结论。凸优化的通用写法是</p>
<p><span class="math display">\[
\min f(x) \\
g_{i} (x) \leq 0, i = 1, ..., m \\
h_{i} (x) = 0, i = 1, ..., p
\]</span></p>
<p>很多地方见到这么写，就是不解释 g、h 是什么，急死个人，对小白很不友好。</p>
<p>这里 <span class="math inline">\(g_{i}(x)\)</span> 是不等式约束函数，为凸函数。</p>
<p><span class="math inline">\(h_{i} (x)\)</span> 是等式约束函数，为仿射函数，仿射函数即相对于线性函数而言， <code>Ax+b</code> 是线性函数，<code>Ax</code>即仿射函数，可以理解为“穿过原点”。</p>
<p>这是用了前面说的凸集中被证明的结论：凸集的交集是凸集，线性等式约束的可行域是凸集，那么就可以用这两点来描述一个更具体的凸优化，分别对应 <span class="math inline">\(g\)</span> 函数集合与 <span class="math inline">\(h\)</span> 函数集合。</p>
<h2 id="局部最优与全局最优">局部最优与全局最优</h2>
<p>目标函数是凸函数、优化变量的可行域是凸集，这两个条件缺其中任何一个都不能保证局部最优解是全局最优解。</p>
<p>也即两者都满足才是凸优化问题，而凸优化问题可以放心地找局部最优，同时也就找到了全局最优。</p>
<p>证明过程也不十分复杂，这里就不照搬资料了。</p>
<h2 id="求解">求解</h2>
<p>梯度下降、牛顿法、拟牛顿法这些研究生课也学过，现在竟不记得那门课叫什么名字，只记得是数学院的老师讲的，十分受用。</p>
<p>难者不会，会者不难。非本篇文章重点，这里掠过。</p>
<p>各种各样的机器学习方法，大都也是在梯度下降的思想上设计的。支持向量机、逻辑回归等等等等。就想起当时老师说：</p>
<blockquote>
<p>模拟退火、遗传算法这些随机算法都发不了什么好期刊了，因为它们不“数学”，收敛靠概率，不能数学地证明收敛时间。而梯度下降、拟牛顿法等等是基于数据梯度方向的，可以严谨地证明收敛性和收敛时间。</p>
</blockquote>
<h2 id="小结">小结</h2>
<p>不求甚解地了解了一下凸优化，背后的数学优美而复杂，而浅尝辄止地理解一下概念未尝不可。</p>

    </div>

    
    
    

    <footer class="post-footer">

        

          <div class="post-nav">
            <div class="post-nav-item">
                <a href="/2021-04-05-federated-learning-start/" rel="prev" title="联邦学习初理解">
                  <i class="fa fa-chevron-left"></i> 联邦学习初理解
                </a>
            </div>
            <div class="post-nav-item">
                <a href="/2021-04-27-try-to-prove-loop-by-kmp/" rel="next" title="试证KMP计算循环节方法">
                  试证KMP计算循环节方法 <i class="fa fa-chevron-right"></i>
                </a>
            </div>
          </div>
    </footer>
  </article>
</div>






    <div class="comments utterances-container"></div>
</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">


<div class="copyright">
  &copy; 
  <span itemprop="copyrightYear">2022</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">CSGrandeur</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" rel="noopener" target="_blank">Hexo</a> & <a href="https://theme-next.js.org/" rel="noopener" target="_blank">NexT.Gemini</a> 强力驱动
  </div>

    </div>
  </footer>

  
  <script src="https://unpkg.com/animejs@3.2.1/lib/anime.min.js" integrity="sha256-XL2inqUJaslATFnHdJOi9GfQ60on8Wx1C2H8DYiN1xY=" crossorigin="anonymous"></script>
  <script src="https://unpkg.com/@next-theme/pjax@0.5.0/pjax.min.js" integrity="sha256-3NkoLDrmHLTYj7csHIZSr0MHAFTXth7Ua/DDt4MRUAg=" crossorigin="anonymous"></script>
<script src="/js/comments.js"></script><script src="/js/utils.js"></script><script src="/js/motion.js"></script><script src="/js/next-boot.js"></script><script src="/js/pjax.js"></script>

  
<script src="https://unpkg.com/hexo-generator-searchdb@1.4.1/dist/search.js" integrity="sha256-1kfA5uHPf65M5cphT2dvymhkuyHPQp5A53EGZOnOLmc=" crossorigin="anonymous"></script>
<script src="/js/third-party/search/local-search.js"></script>





  




  

  <script class="next-config" data-name="enableMath" type="application/json">true</script><script class="next-config" data-name="mathjax" type="application/json">{"enable":true,"tags":"none","js":{"url":"https://unpkg.com/mathjax@3.2.2/es5/tex-mml-chtml.js","integrity":"sha256-MASABpB4tYktI2Oitl4t+78w/lyA+D7b/s9GEP0JOGI="}}</script>
<script src="/js/third-party/math/mathjax.js"></script>


<script class="next-config" data-name="utterances" type="application/json">{"enable":true,"repo":"CSGrandeur/csgrandeur.github.io","issue_term":"pathname","theme":"github-light"}</script>
<script src="/js/third-party/comments/utterances.js"></script>

</body>
</html>
